<template>
  <div id="echarts1"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  props: ['data'],
  data() {
    return {}
  },
  mounted() {
    this.initEcharts()
  },
  methods: {
    initEcharts(data, labels) {
      data,labels
      const chartDom = document.getElementById('echarts1')
      const myChart = echarts.init(chartDom)
      let option

      option = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['新增工单', '完成工单']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: true,
          data: ['2022-9', '2022-10', '2022-11', '2022-12', '2023-01', '2023-02', '2023-03'],
        },
        yAxis: {
          type: 'value',
          name: "单位（件）",
          nameTextStyle: {
            color: "#aaa",
            nameLocation: "start",
          },
        },
        series: [
          {
            name: '新增工单',
            type: 'line',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '完成工单',
            type: 'line',
            data: [220, 182, 191, 234, 290, 330, 310]
          }
        ]
      };

      option && myChart.setOption(option);
    }
  },
  watch: {
    data({data, labels}) {
      this.initEcharts(data, labels)
    }
  }
}
</script>

<style scoped>
#echarts1 {
  width: 100%;
  height: 500px;
}
</style>
